/*
@Copyright:LintCode
@Author:   tjyemail
@Problem:  http://www.lintcode.com/problem/valid-palindrome
@Language: C++
@Datetime: 16-02-09 05:23
*/

class Solution {
public:
    /**
     * @param s A string
     * @return Whether the string is a valid palindrome
     */
    bool isPalindrome(string& s) {
        // Write your code here
        int i=0,j=s.length()-1;
        while(i<j){
            if (!isalnum(s[i])){
                ++i;
                continue;
            }
            if (!isalnum(s[j])){
                --j;
                continue;
            }  
            if (tolower(s[i])==tolower(s[j]))
                ++i,--j;
            else
                return false;
        }
        return true;
    }
};